package com.youaishujuhui.devops.web.service.host;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.nutz.dao.Dao;
import org.nutz.service.IdEntityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.youaishujuhui.devops.web.dao.host.HostDao;
import com.youaishujuhui.devops.web.domain.host.Host;
import com.youaishujuhui.devops.web.po.Select2PO;

@Service
public class HostService extends IdEntityService<Host> {

	@Autowired
	private HostDao hostDao;

	public List<Select2PO> queryProperty(String gameId) {
		List<String> properties = hostDao.queryProperty(gameId);
		List<Select2PO> list = new ArrayList<Select2PO>();
		
		if (properties != null) {
			for (String property : properties) {
				Select2PO po = new Select2PO();
				po.setId(property);
				po.setText(property);
				list.add(po);
			}
		}
		
		return list;
	}

	public List<Select2PO> queryBestDeployHost(int gameId, String property) {
		return hostDao.queryBestDeployHost(gameId, property);
	}
	
	public void IncrCurGameServerCount(int hostId) {
		hostDao.IncrCurGameServerCount(hostId);
	}

	public void updateCurGameServerCount(Host host, int curGameServerCount) {
		host.setCurGameServerCount(curGameServerCount);
		hostDao.updateCurGameServerCount(host);
	}
	
	@Resource(name = "nutDao")
	@Override
	public void setDao(Dao dao) {
		super.setDao(dao);
	}
}
